/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = __stomp_analysis_map_getvalue.c                    */
/*  NOTE      =                                                    */
/*  DATE      = 2015/10/23 by geyh                                 */
/*******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "../../../src/module/stomp/stomp_comm.h"
#include "../../../src/module/stomp/stomp_core.h"
#include "../../../src/module/stomp/config.h"
#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "frbyte_buffer.h"
#include "frlist.h"
#include "frreport_comm.h"

#include "apmtest_cunit.h"
#include "apmtest_comm.h"
static int __suite_init(void)
{

	return 0;
}

static int __suite_cleanup(void)
{

	return 0;
}

extern int __stomp_analysis_map_getvalue(Frreport_body_data *p_st_body_data
        , Frbyte_Packet *p_st_data
        , char *p_key);

static void __case1(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;

    i_ret = apmtest_create_ct(&p_st_conn, stomp_session_destroy, (char *)"192.168.0.1", (char *)"192.168.0.35", 5460, 5672);
    p_st_body_data = frreport_body_new_l7 (p_st_conn);
    
    //测试修改部分
    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data,(char *)"\x72\x00\x0e\x6a\x61\x76\x61\x2e\x6c\x61\x6e\x67\x2e\x42\x79\x74\x65\x9c\x4e\x60\x84\xee\x50\xf5\x1c\x02\x00\x01\x42\x00\x05\x76\x61\x6c\x75\x65\x78\x71\x00\x7e\x00\x04\x39", 43);

    i_ret = __stomp_analysis_map_getvalue(p_st_body_data, p_st_data, (char *)"byte");

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    bytebuff_free(&p_st_data);
    frreport_body_free(&p_st_body_data);
    apmtest_destroy_ct(&p_st_conn);
    return;
}

static void __case2(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;

    i_ret = apmtest_create_ct(&p_st_conn, stomp_session_destroy, (char *)"192.168.0.1", (char *)"192.168.0.35", 5460, 5672);
    p_st_body_data = frreport_body_new_l7 (p_st_conn);

    //测试修改部分
    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data,(char *)"\x72\x00\x11\x6a\x61\x76\x61\x2e\x6c\x61\x6e\x67\x2e\x49\x6e\x74\x65\x67\x65\x72\x12\xe2\xa0\xa4\xf7\x81\x87\x38\x02\x00\x01\x49\x00\x05\x76\x61\x6c\x75\x65\x78\x71\x00\x7e\x00\x04\x00\x00\x00\x01", 49);

    i_ret = __stomp_analysis_map_getvalue(p_st_body_data, p_st_data, (char *)"int");

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    bytebuff_free(&p_st_data);
    frreport_body_free(&p_st_body_data);
    apmtest_destroy_ct(&p_st_conn);
    return;
}

static void __case3(void)
{
    int i_ret = 0;
    Frbyte_Packet *p_st_data = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;

    i_ret = apmtest_create_ct(&p_st_conn, stomp_session_destroy, (char *)"192.168.0.1", (char *)"192.168.0.35", 5460, 5672);


    //测试修改部分
    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data,(char *)"\x72\x00\x11\x6a\x61\x76\x61\x2e\x6c\x61\x6e\x67\x2e\x49\x6e\x74\x65\x67\x65\x72\x12\xe2\xa0\xa4\xf7\x81\x87\x38\x02\x00\x01\x49\x00\x05\x76\x61\x6c\x75\x65\x78\x71\x00\x7e\x00\x04\x00\x00\x00\x01", 49);

    i_ret = __stomp_analysis_map_getvalue(p_st_body_data, p_st_data, (char *)"int");

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    bytebuff_free(&p_st_data);
    apmtest_destroy_ct(&p_st_conn);
//    frreport_body_free(&p_st_body_data);
    return;
}

int add_suite___stomp_analysis_map_getvalue(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __stomp_analysis_map_getvalue()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);


    return FR_SUCC;

}